package com.sg.tr.web;

import java.math.BigInteger;
import java.sql.Timestamp;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.support.SessionStatus;

import com.alibaba.fastjson.JSONArray;
import com.sg.common.empty.core.ConditionRes;
import com.sg.common.empty.core.Conditions;
import com.sg.common.empty.core.FilterVal;
import com.sg.common.empty.service.CfgService;
import com.sg.common.utils.Constant;
import com.sg.common.utils.DateTimeUtils;
import com.sg.tr.service.TrMobService;

@Repository
@Controller
@RequestMapping(value = "/mob")
public class TrMobController {

	private Logger logger = Logger.getLogger(getClass());
	
	@Autowired
	CfgService service;
	
	@Autowired
	TrMobService tmService;
	
	
	/**
	 * “我的”列表
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/myActual/list")
	@ResponseBody
	public Object find(HttpServletRequest request) throws Exception {
//		String route = (String) request.getAttribute("conf.route");

//		Conditions condis = Conditions.init(request);
//		ConditionRes cr = condis.buildCon();
//		String sorts = condis.buildSorts();
//		String limit = condis.buildLimit();
//
//		String orancsql = Constant.get(route + ".csql");
//		String oransql = Constant.get(route + ".sql");
//		orancsql = orancsql.replace("@conditions", cr.getSql()).replace(
//				"@orderby", sorts);
//		oransql = oransql.replace("@conditions", cr.getSql())
//				.replace("@orderby", sorts).replace("@limit", limit);
//		String orancsql="select count(*)  from tr_actual tr where enable='1' and tr.students like ?";
		String code = request.getParameter("code");
//		2019.8.20 更新,部门descr更新为ID
		String oransql="SELECT tr.id,tr.type, tr.date, tr.content, tr.item, tr.orgDescr, tr.post,tr.teacher, tr.students, tr.depId,tr.sumNo,tr.sumRe,tr.fdNo,tr.fdRe FROM tr_actual tr WHERE tr.enable='1' and tr.students like ? and ((tr.sumNo not like ? or tr.sumNo is null) or (tr.fdNo not like ? or tr.fdNo is null)) union SELECT  tr.id,tr.type, tr.date, tr.content, tr.item, tr.orgDescr, tr.post,tr.teacher, tr.students, tr.depId,tr.sumNo,tr.sumRe,tr.fdNo,tr.fdRe FROM tr_actual tr WHERE tr.enable='1' and tr.students like ? and tr.sumNo like ? and tr.fdNo like ? ORDER BY date desc";
//		String oransql="SELECT tr.id,tr.type, tr.date, tr.content, tr.item, tr.orgDescr, tr.post,tr.teacher, tr.students, cfg_org.descr ,tr.sumNo,tr.sumRe,tr.fdNo,tr.fdRe FROM `tr_actual` tr left join cfg_org on tr.depId = cfg_org.id WHERE tr.enable='1' and tr.students like ? and ((tr.sumNo not like ? or tr.sumNo is null) or (tr.fdNo not like ? or tr.fdNo is null)) union SELECT  tr.id,tr.type, tr.date, tr.content, tr.item, tr.orgDescr, tr.post,tr.teacher, tr.students, cfg_org.descr,tr.sumNo,tr.sumRe,tr.fdNo,tr.fdRe FROM `tr_actual` tr left join cfg_org on tr.depId = cfg_org.id WHERE tr.enable='1' and tr.students like ? and tr.sumNo like ? and tr.fdNo like ?";
		String res = "id,type,date,content,item,array`orgDescr,post,array`teacher,array`students,myDept,array`sumNo,sumRe,array`fdNo,fdRe";
//		List<Object> countList = service.queryBySql(orancsql, cr.getParams());
//		String res = Constant.get(route + ".res");
		List<Map<String, Object>> dataList = service.queryBySqlToMap(oransql,
				new Object[]{"%"+code+"%", "%"+code+"%", "%"+code+"%", "%"+code+"%", "%"+code+"%", "%"+code+"%"}, res.split(","));

//		int count = ((BigInteger) countList.get(0)).intValue();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("items", dataList);
//		map.put("total", count);
		map.put("code", 2000);
		return map;
	}
	
	/**
	 * 全部培训记录（显示本人所在部门的所有培训记录），按照培训日期倒序排列
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/allActual/list")
	@ResponseBody
	public Object findAllActualList(HttpServletRequest request) throws Exception {

		String dep = request.getParameter("dep");
		String oransql="SELECT tr.id, tr.type, tr.date, tr.content, tr.item, tr.orgDescr, tr.post,tr.teacher, tr.students, tr.depId FROM tr_actual tr  WHERE tr.enable='1' and tr.depId=? order by date desc";
		String res = "id,type,date,content,item,array`orgDescr,post,array`teacher,array`students,myDept";
		List<Map<String, Object>> dataList = service.queryBySqlToMap(oransql,
				new Object[]{dep}, res.split(","));

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("items", dataList);
		map.put("code", 2000);
		return map;
	}
	
	/**
	 *  "我授课"，按照日期倒序排列
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/myTeachActual/list")
	@ResponseBody
	public Object findMyTeachActualList(HttpServletRequest request) throws Exception {

		String code = request.getParameter("code");
		String oransql="SELECT tr.id,tr.type, tr.date, tr.content, tr.item, tr.orgDescr, tr.post,tr.teacher, tr.students, tr.depId from tr_actual tr WHERE tr.enable='0' and tr.teacher like ? order by date desc";
		String res = "id,type,date,content,item,array`orgDescr,post,array`teacher,array`students,myDept";
		List<Map<String, Object>> dataList = service.queryBySqlToMap(oransql,
				new Object[]{"%"+code+"%"}, res.split(","));

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("items", dataList);
		map.put("code", 2000);
		return map;
	}
	
	/***
	 * 培训详细信息
	 * @param request
	 * @param requestBody
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/{tb2}/detail")
	@ResponseBody
//	@Transactional
	public Object detail(HttpServletRequest request,
			@RequestBody Map<String, Object> requestBody) throws Exception {
//		String taskId = requestBody.get("taskId").toString();
		String eventId = requestBody.get("eventId").toString();
//		String sys = requestBody.get("sys").toString();
		Map<String, Object> map = new HashMap<String, Object>();
		try {

			String scRes = "优先级别,计划类型,培训日期,培训时间,培训地点,培训课时,培训班组,培训岗位,授课人,培训对象,培训形式,培训类别,培训项目,培训目的,培训内容,培训材料,培训状态";
			List<Map<String, Object>> taskList = service.queryBySqlToMap(
					"SELECT level,type,date,time,place,hour,orgDescr,post,teacher,students,form,cate,item,aim,content,files,enable FROM tr_actual where id=?",
					new String[] { eventId }, scRes.split(","));
			Map<String, Object> taskMap=taskList.get(0);
			Iterator it = taskMap.keySet().iterator();
			List<Object> task=new ArrayList<>();
			while (it.hasNext()) {
				String key = it.next().toString();
				String value="";
				Object o=taskMap.get(key);
				if(o!=null)
				{
					value=o.toString();
				}
				Map<String, Object> km = new HashMap<String, Object>();
				km.put("label", key);
				km.put("value", value);
				task.add(km);
			}
			map.put("items", task);
			map.put("code", 2000);
		} catch (Exception e) {
			logger.error(e.getMessage());
			map.put("code", 5030);
			map.put("msg", "更新发生内部错误，请联系管理员");
		}
		return map;
	}
	
	/**
	 * 培训小结信息展示
	 * @param request
	 * @param requestBody
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/summary/info")
	@ResponseBody
	public Object sum(HttpServletRequest request,
			@RequestBody Map<String, Object> requestBody) throws Exception{
			String actualId = requestBody.get("eventId").toString();
			String code = requestBody.get("code").toString();
//			String res = "id,code,name,sum,array`attach";
			String res = "id,code,name,sum,attach";
			String sql = "select id,code,name,sum,attach from tr_sum where actual=? and code=?";
//			String res = "id,code,name,sum,array`attach,isFinished";
//			String sql = "select id,code,name,sum,attach,isFinished from tr_sum where actual=? and code=?";
			List<Map<String, Object>> sumList = service.queryBySqlToMap(sql, new Object[]{actualId, code}, res.split(","));
			Map<String, Object> map = new HashMap<String, Object>();
			
			if(!sumList.isEmpty()){
				map.put("summary", sumList.get(0));
				map.put("code", 2000);
			}else{
				map.put("code", 2500);
				map.put("msg", "!!!");
			}
			return map;
		
	}
	
	/***
	 * 培训小结信息更新
	 * @param request
	 * @param requestBody
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/summary/update")
	@ResponseBody
	public Object sUp(HttpServletRequest request,
			@RequestBody Map<String, Object> requestBody) throws Exception{
//		Object id = requestBody.get("id");
		HashMap<String, Object> summary = (HashMap<String, Object>)requestBody.get("summary");
		Object id = summary.get("id");
		Object sum = summary.get("sum");
		Object attach = summary.get("attach");
//		Object isFinished = summary.get("isFinished");
		Object actualId = requestBody.get("actualId");
		Object code = summary.get("code");
		Object name = summary.get("name");
		Map<String, Object> map = new HashMap<String, Object>();
		if(id!=null){//更新
//			String id = requestBody.get("id").toString();
			String upSql = "update tr_sum set sum=?,attach=? where id=?";
			service.excuteBySql(upSql, new Object[]{sum, attach, id});
//			service.excuteBySql(upSql, new Object[]{sum, JSONArray.toJSONString(attach), id});
			map.put("code", 2000);
		}else{//新增
			//小结记录新增，培训实际中相关记录更新
			tmService.sumAdd(sum, attach, actualId, code, name);
			map.put("code", 2000);
		}
		return map;
	}

	
	
	/***
	 * 培训反馈信息展示
	 * @param request
	 * @param requestBody
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/fd/info")
	@ResponseBody
	public Object fd(HttpServletRequest request,
			@RequestBody Map<String, Object> requestBody) throws Exception{
			String actualId = requestBody.get("eventId").toString();
			String code = requestBody.get("code").toString();
			String res = "id,code,name,rele,sub,cour,expe,easy,smoo,mode,appl,pre,cle,work,"
					+ "help,part,exer,judg,wort,disl,adju";
			String sql = "select id,code,name,rele,sub,cour,expe,easy,smoo,mode,appl,pre,cle,work,"
					+ "help,part,exer,judg,wort,disl,adju from tr_fd where actual=? and code=?";
			List<Map<String, Object>> fd = service.queryBySqlToMap(sql, new Object[]{actualId, code}, res.split(","));
			Map<String, Object> map = new HashMap<String, Object>();
			
			if(!fd.isEmpty()){
				map.put("fd", fd.get(0));
				map.put("code", 2000);
			}else{
				map.put("code", 2500);
				map.put("msg", "!!!");
			}
			return map;
		
	}
	
	/***
	 * 培训反馈填写及更新
	 * @param request
	 * @param requestBody
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/fd/update")
	@ResponseBody
	public Object fUp(HttpServletRequest request,
			@RequestBody Map<String, Object> requestBody) throws Exception{
		HashMap<String, Object> fd = (HashMap<String, Object>)requestBody.get("fd");
		Object id = fd.get("id");
		Object rele = fd.get("rele");
		Object sub = fd.get("sub");
		Object cour = fd.get("cour");
		Object expe = fd.get("expe");
		Object easy = fd.get("easy");
		Object smoo = fd.get("smoo");
		Object mode = fd.get("mode");
		Object appl = fd.get("appl");
		Object pre = fd.get("pre");
		Object cle = fd.get("cle");
		Object work = fd.get("work");
		Object help = fd.get("help");
		Object part = fd.get("part");
		Object exer = fd.get("exer");
		Object judg = fd.get("judg");
		Object wort = fd.get("wort");
		Object disl = fd.get("disl");
		Object adju = fd.get("adju");
		Object code = fd.get("code");
		Object name = fd.get("name");
//		String work = requestBody.get("easy").toString();
		String actualId = requestBody.get("actualId").toString();
		Map<String, Object> map = new HashMap<String, Object>();
		if(id!=null){//更新
//			String id = requestBody.get("id").toString();
			String upSql = "update tr_fd set rele=?,sub=?,cour=?,expe=?,easy=?,smoo=?,mode=?,appl=?,pre=?,cle=?,work=?,help=?,"
					+ "part=?,exer=?,judg=?,wort=?,disl=?,adju=? where id=?";
			service.excuteBySql(upSql, new Object[]{rele, sub, cour, expe, easy, smoo, mode, appl, pre, cle, work, help, part, exer, judg, wort, disl, adju, id});
			map.put("code", 2000);
		}else{//新增
			//培训反馈记录增加，培训实际相关记录更新
			tmService.fdAdd(rele, sub, cour, expe, easy, smoo, mode, appl, pre, cle,
					work, help, part, exer, judg, wort, disl, adju, code, name,
					actualId);
			map.put("code", 2000);
		}
		return map;
	}

	/**
	 * 获取培训对象信息,由授课人选择需要发送签到验证人员
	 * @param request
	 * @param requestBody
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/regList/list")
	@ResponseBody
	public Object regList(HttpServletRequest request,
			@RequestBody Map<String, Object> requestBody) throws Exception{
			String actualId = requestBody.get("eventId").toString();
//			String code = requestBody.get("code").toString();
//			String res = "students,regNo";
			String res = "array`students,array`regNo";
			String sql = "SELECT tr.students, tr.regNo from tr_actual tr where tr.enable='0' and id=?";
			List<Map<String, Object>> regList = service.queryBySqlToMap(sql, new Object[]{actualId}, res.split(","));
			Map<String, Object> map = new HashMap<String, Object>();
			if(!regList.isEmpty()){
				map.put("item", regList.get(0));
				map.put("code", 2000);
			}else{
				map.put("code", 2500);
				map.put("msg", "未获取到培训信息,请确认！");
			}
			return map;
		
	}
	
	/**
	 * 授课人发起签到验证
	 * @param request
	 * @param requestBody
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/reg/send")
	@ResponseBody
	public Object regRecord(HttpServletRequest request,
			@RequestBody Map<String, Object> requestBody) throws Exception{
			Map<String, Object> map = new HashMap<String, Object>();
//			try{
				tmService.initSign(requestBody);
//			}catch (Exception e) {
//				logger.error(e.getMessage());
//				map.put("code", 5030);
//				map.put("msg", "程序发生内部错误，请联系管理员");
//			}
			map.put("code", 2000);
			return map;
		
	}

	
	/**
	 * 个人手机端签到功能
	 * @param request
	 * @param requestBody
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/actual/sign")
	@ResponseBody
	public synchronized Object sign(HttpServletRequest request,
			@RequestBody Map<String, Object> requestBody) throws Exception{
		String actualId = requestBody.get("actualId").toString();
		String code = requestBody.get("code").toString();
		String name = requestBody.get("name").toString();
		
		Map<String, Object> map = new HashMap<String, Object>();
		
		String actualSql = "select enable,date from tr_actual where id=?";
		String resActual = "enable,date";
		List<Map<String, Object>> actualList = service.queryBySqlToMap(actualSql, new Object[]{actualId}, resActual.split(","));
		if(actualList.size()>0){
			Map<String, Object> actualRes = actualList.get(0);
			String actualEnable = actualRes.get("enable").toString();
//			actual状态:0,未完成;1,已完成;-1,已取消
			if(StringUtils.equals(actualEnable, "0")){
				String regSql = "select regDate,enable from tr_reg where actual=? and code=? and name=?";
				String res2 = "regDate,enable";
				List<Map<String, Object>> regList = service.queryBySqlToMap(regSql, new Object[]{actualId, code, name}, res2.split(","));
				if(regList.size()>0){
					Map<String, Object> regRes = regList.get(0);
					String enable = regRes.get("enable").toString();
					
					if(StringUtils.equals(enable, "1")){		//已签到
						map.put("code", 4000);
						map.put("msg", "已完成签到,请勿重复签到");
					}else{					//签到
						tmService.signAuto(actualId, code, name);
						map.put("code", 2000);
//						map.put("msg", "签到成功!");
					}
				}else{
					map.put("code", 3000);
					map.put("msg", "无此培训信息");
				}
			}else{
				map.put("code", 5000);
				map.put("msg", "培训已完成(签到超时),无法签到");
			}
		}else{
			map.put("code", 3000);
			map.put("msg", "无此培训信息");
		}
		return map;
	}

	
	/**
	 * 移动端个人情况展示
	 * @param request
	 * @param requestBody
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/member/info")
	@ResponseBody
	public Object getPerInfo(HttpServletRequest request ) throws Exception{
			String code = request.getParameter("code").toString();
			
		    String remoteAddr = request.getRemoteAddr();//得到来访者的IP地址
		    String name = "";//获取来访者的名字
//		    String remoteUser = request.getRemoteUser();
//			String res = "id,name,code,gendr,orgDescr,station,postDescr,inDate,inLen,title,certf,dept";
//			String sql = "select `member`.`id` AS `id`,`member`.`descr` AS `descr`,`member`.`code` AS `code`,`member`.`gendr` AS `gendr`,`org`.`descr` AS `orgDescr`,`member`.`station` AS `station`,`post`.`descr` AS `postDescr`,`member`.`inDate` AS `inDate`,`member`.`inLen` AS `inLen`,`member`.`title` AS `title`,`member`.`certf` AS `certf`,`member`.`dept` AS `dept` from ((`cfg_member` `member` left join `cfg_org` `org` on((`member`.`org` = `org`.`id`))) left join `cfg_post` `post` on((`member`.`post` = `post`.`id`))) where ((`member`.`delfg` = '0') and (`org`.`orge` = '1000') and (`member`.`code` like '2%')) and member.code= ?";
//			String eventId = requestBody.get("eventId").toString();
			Map<String, Object> map = new HashMap<String, Object>();
			try {

				String scRes = "姓名,工号,性别,组织描述,车站,岗位描述,本单位报道日期,民族,政治面貌,线别";
				String sql = "select member.descr AS descr,member.code AS code,REPLACE(REPLACE(member.sex, 0, _utf8 '女' ),1,_utf8 '男')AS gendr,org.descr AS orgDescr,cfg_org.descr AS stationDescr,post.descr AS postDescr,member.regtd AS regtd,member.natin AS natin,member.polaf AS polaf,member.linid AS linid from ((cfg_member member left join cfg_org org on((member.org = org.id))) left join cfg_post post on((member.post = post.id)) left join cfg_org on (member.station = cfg_org.code)) where ((member.delfg = '0') and (org.orge = '1000') and (member.code like '2%')) and member.code= ?";
				List<Map<String, Object>> taskList = service.queryBySqlToMap(
						sql, new String[] { code }, scRes.split(","));
				Map<String, Object> taskMap=taskList.get(0);
				Iterator it = taskMap.keySet().iterator();
				List<Object> task=new ArrayList<>();
				while (it.hasNext()) {
					String key = it.next().toString();
					String value="";
					Object o=taskMap.get(key);
					if(o!=null)
					{
						value=o.toString();
					}
					Map<String, Object> km = new HashMap<String, Object>();
					km.put("label", key);
					km.put("value", value);
					task.add(km);
//                  获取来访者的姓名
					if(StringUtils.equals(key, "姓名")){
						name = value;
					}
					
				}
				map.put("items", task);
				map.put("code", 2000);
			} catch (Exception e) {
				logger.error(e.getMessage());
				map.put("items", new ArrayList<>());
				map.put("code", 2000);
//				map.put("code", 5030);
//				map.put("msg", "更新发生内部错误，请联系管理员");
			}
			
//			获取来访信息，并保存进数据库
			String now = DateTimeUtils.formatDate(
					new Timestamp(System.currentTimeMillis()), "yyyy-MM-dd HH:mm");
			String nid = (String) FilterVal.init("sys32Id", service).get2();
			String visitSql = "insert into tr_visitcount (id, code, name, ip, visitTime) values(?, ?, ?, ?, ?)";
			service.excuteBySql(visitSql, new Object[]{nid, code, name, remoteAddr, now});
			
			return map;
		
	}
	
	/**
	 * 移动端“近期课程”列表展示
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/tr/member/class")
	@ResponseBody
	public Object classList (HttpServletRequest request) throws Exception{
		String now = DateTimeUtils.formatDate(
				new Timestamp(System.currentTimeMillis()), "yyyy-MM-dd");
//		统计近一个月内的课程
		String monthLater = DateTimeUtils.formatDate(
				new Timestamp((long) (System.currentTimeMillis() + 30.42*24*3600*1000)), "yyyy-MM-dd");
		
		String code = request.getParameter("code");
		String oranSql = "select item,date from tr_actual where enable='0' and students like ? and date >= ? and date <= ?";
		String res = "item,date";
		
		List<Map<String, Object>> dataList = service.queryBySqlToMap(oranSql, new Object[]{"%"+code+"%", now, monthLater}, res.split(","));
		List<Map<String, Object>> items = new ArrayList<Map<String,Object>>();
		for(Map<String ,Object> task : dataList){
			Map<String, Object> tMap = new HashMap<String, Object>();
			tMap.put("label", task.get("item"));
			tMap.put("value", task.get("date"));
			items.add(tMap);
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("items", items);
		map.put("code", 2000);
		return map;
		
	}
	
/**
 * 课程统计模块内容及数据展示
 * @param request
 * @return
 * @throws Exception
 */
@RequestMapping("/tr/resum/claStat")
@ResponseBody
	public Object getClaStat (HttpServletRequest request,
			@RequestBody Map<String, Object> requestBody) throws Exception{
//	String code =  request.getParameter("code");
	String keyWord = "course";
	String code = requestBody.get("userCode").toString();
	String position = requestBody.get("position").toString();
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String, Object>> items = new ArrayList<Map<String,Object>>();
			String scRes2 = "descr,value";
			String sql2 = "SELECT descr,value from tr_resum where enable='1' and num =? and post=? and keyWord=? order by ordInd ASC";
			List<Map<String, Object>> taskList = service.queryBySqlToMap(
					sql2, new String[] {code, position,  keyWord}, scRes2.split(","));
			for(Map<String ,Object> task : taskList){
				Map<String, Object> tMap = new HashMap<String, Object>();
				tMap.put("label", task.get("descr"));
				tMap.put("value", task.get("value"));
				items.add(tMap);
			}
		map.put("items", items);
		map.put("code", 2000);
		return map;
		
	}

/**
 * 课时统计模块内容及数据展示
 * @param request
 * @return
 * @throws Exception
 */
@RequestMapping("/tr/resum/hourStat")
@ResponseBody
	public Object getHourStat (HttpServletRequest request,
			@RequestBody Map<String, Object> requestBody) throws Exception{
//	String code =  request.getParameter("code");
//	String keyWord = requestBody.get("keyWord").toString();
	String keyWord = "hour";
	String code = requestBody.get("userCode").toString();
	String position = requestBody.get("position").toString();
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String, Object>> items = new ArrayList<Map<String,Object>>();
			String scRes2 = "descr,value";
			String sql2 = "SELECT descr,value from tr_resum where enable='1' and num = ? and post=? and keyWord=? order by ordInd ASC";
			List<Map<String, Object>> taskList = service.queryBySqlToMap(
					sql2, new String[] {code, position, keyWord }, scRes2.split(","));
			for(Map<String ,Object> task : taskList){
				Map<String, Object> tMap = new HashMap<String, Object>();
				tMap.put("label", task.get("descr"));
				tMap.put("value", task.get("value"));
				items.add(tMap);
			}
		map.put("items", items);
		map.put("code", 2000);
		return map;
		
	}


/**
 * 移动端“技术比武”列表展示
 * @param request
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/tr/member/techComp")
@ResponseBody
public Object getTechComp (HttpServletRequest request) throws Exception{
	String code = request.getParameter("code");
//	String oranSql = "SELECT awaDescr,compDescr, compLevel,compTime FROM tr_techcomp where code=? ORDER BY compTime desc";
	Map<String, Object> map = new HashMap<String, Object>();
	try {

		String scRes = "获奖情况,比武名称,比武层级,比武时间";
		String sql = "SELECT awaDescr,compDescr, compLevel,compTime FROM tr_techcomp where code=? ORDER BY compTime desc";
		List<Map<String, Object>> taskList = service.queryBySqlToMap(
				sql, new String[] { code }, scRes.split(","));
		List<Object> task=new ArrayList<>();
		for(int i=0;i<taskList.size();i++){
			Map<String, Object> taskMap=taskList.get(i);
			Iterator it = taskMap.keySet().iterator();
		
			while (it.hasNext()) {
				String key = it.next().toString();
				String value="";
				Object o=taskMap.get(key);
				if(o!=null)
				{
					value=o.toString();
				}
				Map<String, Object> km = new HashMap<String, Object>();
				km.put("label", key);
				km.put("value", value);
				task.add(km);
			}
		}
		
		map.put("items", task);
		map.put("code", 2000);
	} catch (Exception e) {
		logger.error(e.getMessage());
		map.put("items", new ArrayList<>());
		map.put("code", 2000);
//		map.put("code", 5030);
//		map.put("msg", "更新发生内部错误，请联系管理员");
	}
	return map;
	
}




/**
 * 定时任务,每天根据(工号/岗位)信息查询个人培训统计数据,并插入或更新至tr_resum表中
 * @return
 * @throws Exception
 */
@RequestMapping("/tr/resum/cour")
@ResponseBody
	public Object getCourseSta () throws Exception{
		tmService.getCourseSta();
		return null;
	}

}
